<?PHP 
include_once 'setup/setup.php';
include("./fckeditor/fckeditor.php") ;
/* count */

$query="SELECT count(*) FROM e_puser";
$rs = $dbh->query($query);
$total =  $rs->fetchColumn();	

switch($_GET['act'])
{
	case 'add':
				$stmt = $dbh->prepare("INSERT INTO  e_paper (e_title,e_content,e_date) VALUES (?,?,now())");
				$stmt->bindParam(1,$_POST['e_title'],PDO::PARAM_STR);
				$stmt->bindParam(2,htmlentities(stripslashes($_POST['e_content']),ENT_QUOTES,"UTF-8"),PDO::PARAM_STR);
				$stmt->execute();
				header("location:post_list.php");
				break;
	case "edit":
				$stmt = $dbh->prepare("SELECT * FROM e_paper WHERE e_id=? ");
				$stmt->bindParam(1,$_GET['g'],PDO::PARAM_INT);
				$stmt->execute();	
				$stmt->setFetchMode(PDO::FETCH_ASSOC);
				$datas=$stmt->fetch();;
				break;
	case "update":
				$stmt = $dbh->prepare("UPDATE e_paper  SET e_title= ?,e_content= ? WHERE e_id=?");				
				$stmt->bindParam(1,$_POST['e_title'],PDO::PARAM_STR );
				$stmt->bindParam(2,$_POST['e_content'],PDO::PARAM_STR);
				$stmt->bindParam(2,htmlentities(stripslashes($_POST['e_content']),ENT_QUOTES,"UTF-8"),PDO::PARAM_STR);
				$stmt->bindParam(3,$_POST['e_id'],PDO::PARAM_INT);
				$stmt->execute();	
				header("location:post_list.php");			
				break;				

}
$sBasePath="./fckeditor/";
#echo html_entity_decode($dbh->quote($datas['e_content']),ENT_QUOTES,"UTF-8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.2.0/build/reset-fonts-grids/reset-fonts-grids.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/base/base-min.css">
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用者列表</title>
</head>
<body>
<div id="man">
<div class="h_line"><?php if(!$_GET['g']){ ?>新增<?php }else{ ?>修改<?php }?>電子報</div>
<div style="padding:5px;">
| <a href="post_list.php">電子報列表</a> | <a href="user_list.php">使用者列表</a> | 新增電子報 | <a href="#3">發送測試</a> |</div>

<?php if(!$_GET['g']) { ?>
<form action="?act=add" method="post" enctype="multipart/form-data">
<?php }else{ ?>
<form action="?act=update" method="post" enctype="multipart/form-data">
<?php } ?>
<span class="style1">標題：</span>
<input name="e_title" type="text" id="e_title" size="80" maxlength="255" class="style1"  value="<?php echo $datas['e_title'];?>"/>
<input name="e_id" type="hidden" value="<?php echo $datas['e_id'];?>" />
 <?php 
$oFCKeditor = new FCKeditor("e_content") ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->ToolbarSet = 'Basic';
$oFCKeditor->Width  = '100%' ;
$oFCKeditor->Height = '300' ;
$oFCKeditor->Value		= html_entity_decode($datas['e_content'],ENT_QUOTES,"UTF-8");
$oFCKeditor->Create() ;
?>
 <input type="submit" name="Submit" value="確定" class="style1" />
</form>

</body>
</html>

